<?PHP
/*
 * $Id: SystemTest.class.php 159 2009-12-16 15:59:51Z namba0219 $
 * =============================================================================
 * Barge - Web application framework on PHP5
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * =============================================================================
 * For more information, see http://barge.googlecode.com/
 */
namespace barge;

use \UnitTestCase;

use barge\System;
use barge\ClassLoader;
use barge\utils\ArrayList;
use barge\utils\HashMap;
use barge\utils\IndexOutOfBoundsException;
use barge\utils\IllegalAccessException;
use barge\logging\LogFactory;

/**
 * @see UnitTestCase
 */
class SystemTest extends UnitTestCase
{
	/**
	 * @test
	 */
	public function testGetBaseDir()
	{
		$this->assertNotNull(System::getBaseDir());
	}

	/**
	 * @test
	 */
	public function testGetClassLoader()
	{
		$this->assertIsA(System::getClassLoader(), 'barge\ClassLoader');
	}

	/**
	 * @test
	 */
	public function testProperty()
	{
		System::setProperty('Test/key', 'value');
		$this->assertIdentical(System::getProperty('Test/key'), 'value');

//		System::setPropertyFile();
		// TODO :
	}

	/**
	 * @test
	 */
	public function testGetRealPath()
	{
		System::setBaseDir('/');
		$this->assertIdentical(realpath(System::getBaseDir()), realpath(System::getRealPath('/')));
		$this->assertIdentical('/index.html', System::getRealPath('index.html'));
		System::setBaseDir(__DIR__);
		$this->assertIdentical(realpath(__DIR__), realpath(System::getRealPath('/')));
	}

	/**
	 * @test
	 */
	public function testWorkDir()
	{
		$this->assertNotNull(System::getWorkDir());
		System::setWorkDir('/temp');
		$this->assertIdentical(System::getWorkDir(), '/temp');
	}

	/**
	 * @test
	 */
	public function testCurrentTime()
	{
		$this->assertNotNull(System::currentTime());
	}

	/**
	 * @test
	 */
	public function testCurrentMicroTime()
	{
		$this->assertNotNull(System::currentMicroTime());
	}

	/**
	 * @test
	 */
	public function testGetFreeDiskspace()
	{
		$this->assertTrue(System::getFreeDiskspace() === disk_free_space('/'));
		$this->assertTrue(System::getFreeDiskspace() > 0);
	}

	/**
	 * @test
	 */
	public function testGetTotalDiskspace()
	{
		$this->assertIdentical(System::getTotalDiskspace(), disk_total_space('/'));
		$this->assertTrue(System::getTotalDiskspace() > 0);
	}

	/**
	 * @test
	 * @see Runtime#registerShutdownHandler
	 */
	public function testRegisterShutdownHandler()
	{
		System::registerShutdownHandler(new _TestShutdownHandler());
	}

}

/**
 * @see ShutdownHandler
 */
class _TestShutdownHandler implements ShutdownHandler
{
	/**
	 * @param mixed $parameter
	 */
	public function shutdown($parameter)
	{
		echo 'shutdown';
	}
}